﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChineseAreaService
{

    public static class ChineseAreaServiceExtensions
    {

        public static bool IsIncluded(this IChinaAreaService service, string code, string parent)
        {
            if (string.IsNullOrEmpty(code))
            {
                if (string.IsNullOrEmpty(parent))
                {
                    return true;
                }
                throw new ArgumentException("code");
            }
            if (string.IsNullOrEmpty(parent))
            {
                return true;
            }
            return code.StartsWith(parent);
        }

        public static string GetAreaNameEx(this IChinaAreaService service, string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return string.Empty;
            }
            return service.GetAreaName(code, true);
        }

        public static string ShortenAreaName(this IChinaAreaService service, string name)
        {
            return name?.Replace("北京北京", "北京").Replace("上海上海", "上海").Replace("天津天津", "天津").Replace("重庆重庆", "重庆");
        }

    }

}